class MyPageHeader extends BaseEditMaster {
    constructor(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
            returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl) {
        super(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
                returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl);
        super.SetHasFileterValue(true);   // 目的是采用自定义的过滤条件
    }
    // 得到数据
    GetEntityData() {
        var item = {};
        item['businessCardId'] = $("#BusinessCardId").val();
        item['userId'] = $.trim($("#UserId").val());
        item['cardName'] = $.trim($("#CardName").val());
        item['companyName'] = parent.formatNullInputValue($.trim($("#CompanyName").val()));
        item['job'] = parent.formatNullInputValue($.trim($("#Job").val()));
        item['companyAddress'] = parent.formatNullInputValue($.trim($("#CompanyAddress").val()));
        item['tel'] = parent.formatNullInputValue($.trim($("#Tel").val()));
        item['fax'] = parent.formatNullInputValue($.trim($("#Fax").val()));
        item['mobil'] = parent.formatNullInputValue($.trim($("#Mobil").val()));
        item['email'] = parent.formatNullInputValue($.trim($("#Email").val()));
        item['http'] = parent.formatNullInputValue($.trim($("#Http").val()));
        item['description'] = parent.formatNullInputValue($.trim($("#Description").val()));
        item['createdBy'] = $("#UserId").val();
        item['updatedBy'] = $("#UserId").val();

        return JSON.stringify(item);
    }
    GetFilterValue() {
        let params = {};
        params['UserId'] = $.trim($("#UserId").val());
        params['BusinessCardId'] = this.dataId; //$.trim($("#BusinessCardId").val());

        return params;
    }
    FillData(data) {
        $("#BusinessCardId").val(data.businessCardId);
        this.dataId = data.businessCardId;
        $("#UserId").val(data.userId);
        $("#CardName").val(data.cardName);
        $("#CompanyName").val(data.companyName);
        $("#Job").val(data.job);
        $("#CompanyAddress").val(data.companyAddress);
        $("#Tel").val(data.tel);
        $("#Fax").val(data.fax);
        $("#Mobil").val(data.mobil);
        $("#Email").val(data.email);
        $("#Http").val(data.http);
        $("#Description").val(data.description);

        this.currentTaskPrivileges = data.currentTaskPrivileges;
        this.nextTaskPrivileges = data.nextTaskPrivileges;

        this.SetPageElementStatus();
    }
    SetPageElementStatus() {
        super.SetPageElementStatus(function () {
        }, function () {
        }, function () {
        });
    }
    // 【保存】按钮
    DoSave() {
        // step 1、进行页面验证，失败则返回
        if (!$("#form_data").valid())
            return;

        this.saveUrl = "/oa/business_card/update.html";
        if (parseInt($("#BusinessCardId").val()) === 0) {
            this.saveUrl = "/oa/business_card/insert.html";
        }

        // step 2、设置结果（保存成功）
        super.Save(function (data, _this) {
            if (_this.pageStatus === 1) {
                $("#BusinessCardId").val(data.Key);
                _this.dataId = data.Key;
                _this.pageStatus = 2;
            }
        });
    }
    New() {
        super.New();
        // 默认设置一些值
        $("#BusinessCardId").val(0);
        $("#CardName").focus();
    }
}

let _InstancePageHeader = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let _pageStatus = $("#Action").val();
    let _dataId = $("#BusinessCardId").val();
    let business_card_list_result = $.cookie("business_card_list_result") === undefined ? "" : $.cookie("business_card_list_result");
    let _pageListData = [];
    if (business_card_list_result !== "") {
        _pageListData = business_card_list_result.split(',');
        $("#rec_total_rows").text(_pageListData.length); //总页数
        $("#rec_cur_row").text($.inArray(_dataId, _pageListData) + 1); // 当前页数

        if (_pageListData.length > 0) {
            let index = $.inArray(_dataId, _pageListData);
            if (index === 0) {
                $("#ButPrev").attr("disabled", "disabled");
            } else {
                $("#ButNext").removeAttr("disabled");
            }
            if (index === (_pageListData.length - 1)) {
                $("#ButNext").attr("disabled", "disabled");
            } else {
                $("#ButPrev").removeAttr("disabled");
            }
        }
    } else {
        $("#rec_total_rows").text("1");
        $("#rec_cur_row").text("1");
    }

    _InstancePageHeader = new MyPageHeader(_dataId, 0, 0, _pageStatus, _pageListData,
            "/oa/business_card/list.html",
            "/oa/business_card/fetchByKey.html",
            null,
            "/oa/business_card/export.html", "/oa/business_card/print.html");

    _InstancePageHeader.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
}

//-----------------------------------------------------------------------------
// 验证函数
//-----------------------------------------------------------------------------
$.validator.setDefaults({
    ignore: 'hidden, [reaonly=readonly]'
});
$.validator.addMethod("valueNotEquals", function (value, element, arg) {
    return arg !== value;
}, "Value must not equal arg.");

$(function () {
    $("#form_data").validate({
        // Step 1：设置验证规则和错误消息
        rules: {
            _CardName: "required"
        },
        messages: {
            _CardName: "请填写名片人。"
        },
        // Step 2：设置验证触发事件
        onclick: false,
        onfocusout: false,
        onfocusin: false,
        onkeyup: false,
        onkeydown: false,
        focusInvalid: false,
        // Step 3：设置错误信息提示
        showErrors: window.showErrors  //使用自定义的错误显示方法
    });
});





















